package com.compty.paint.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.compty.paint.domain.CustomerInfo;
import com.compty.paint.util.Constants;


public class CustomerLogonCheckServlet extends HttpServlet{

	private static final long serialVersionUID = 4378358549631302991L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setCharacterEncoding("utf-8");
		HttpSession session = request.getSession();
		PrintWriter out = response.getWriter();
		Object customerInfo =  session.getAttribute(Constants.CustomerInfo);
		String context = request.getContextPath();
		
		if( customerInfo != null){
			String userName = ((CustomerInfo)customerInfo).getUserName();
			String returnMsg =  userName+",<a href=\""+context+"/customer/customerAction!index.do\" style=\"color: #979797\">我的订单</a>|<a href=\""+context+"/customer/customerAction!logout.do\" style=\"color: #979797\">退出</a>";
			out.print(returnMsg);
		}else{
			String returnMsg =  "<a href=\"javascript:toLogon('"+context+"')\" style=\"color: #979797\">会员登录</a>&nbsp;|&nbsp;<a href=\"javascript:toRegister('"+context+"')\" style=\"color: #979797\">免费注册</a>";
			out.print(returnMsg);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}


}
